package cn.qzzg.common.exceptlion;

import cn.qzzg.common.ResultBean;
import cn.qzzg.enums.CodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局异常处理器
 */
@RestControllerAdvice
public class GlobalExceptionHandler {
    /**
     * 运行时异常
     */
    @ExceptionHandler(CommonException.class)
    public ResultBean<?> commonException(CommonException ex) {
        return ResultBean.error(ex.getCode());
    }

    /**
     * 运行时异常
     */
    @ExceptionHandler(RuntimeException.class)
    public ResultBean<?> runtimeException(RuntimeException ex) {
        ex.printStackTrace();
        return ResultBean.error(CodeEnum.SYSTEM_ERROR_B0001);
    }
}